package org.budo.icbc.sdk.util;

public class RSAUtil {

    public static String pubkeyEncrypt(String pubkey, String content) throws Exception {

        System.out.println("--------------公钥加密私钥解密过程-------------------");
        // 公钥加密过程
        byte[] cipherData = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(pubkey), content.getBytes());
        String cipher = RSABase64Util.encode(cipherData);
        return cipher;
    }

//公钥解密过程
    public static String prikeyDecrypt(String prikey, String content) throws Exception {
        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(prikey), RSABase64Util.decode(content));
        String restr = new String(res);
        return restr;
    }

    public static String prikeyEncrypt(String prikey, String content) throws Exception {
        // 公钥加密过程
        byte[] cipherData = RSAEncrypt.encrypt(RSAEncrypt.loadPrivateKeyByStr(prikey), content.getBytes());
        String cipher = RSABase64Util.encode(cipherData);
        return cipher;
    }

//公钥解密过程
    public static String pubkeyDecrypt(String pubkey, String content) throws Exception {
        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPublicKeyByStr(pubkey), RSABase64Util.decode(content));
        String restr = new String(res);
        return restr;
    }
}